package com.cskaoyan.controller.orderController;

import com.cskaoyan.model.bean.OrderGoods;
import com.cskaoyan.model.bo.orderwx.CskaoyanmallOrderGoods;
import com.cskaoyan.model.bo.orderwx.OrderCommentWxBo;
import com.cskaoyan.model.vo.BaseRespVo;
import com.cskaoyan.model.vo.orderwx.OrderDetailWxVo;
import com.cskaoyan.model.vo.orderwx.OrderListWcVo;
import com.cskaoyan.service.orderwx.OrderWxService;
import com.cskaoyan.service.orderwx.WxOrderService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/wx/order")

public class OrderWxController {


    @Autowired
    OrderWxService orderWxService;

    @Autowired
    WxOrderService wxOrderService;

   
    @GetMapping("/list")
    public BaseRespVo OrderWxList(int size, int page, int showType) {
//        int size = (int) map.get("size");
//        int page = ((int) map.get("page"));
//        int showType = (int) map.get("showType");
        String username = (String) SecurityUtils.getSubject().getPrincipal();

        OrderListWcVo orderListWcVo = orderWxService.getWxOrderList(showType, page, size, username);

        return BaseRespVo.ok(orderListWcVo);
    }


    @GetMapping("/detail")
    public BaseRespVo OrderWxDetail(int orderId) {
//        int orderId = (int) map.get("orderId");

        OrderDetailWxVo orderDetailWxVo = orderWxService.getWxOrderDetailt(orderId);

        return BaseRespVo.ok(orderDetailWxVo);
    }

    @PostMapping("/comment")
    public BaseRespVo OrderWxComment(@RequestBody OrderCommentWxBo orderCommentWxBo) {
        String username = (String) SecurityUtils.getSubject().getPrincipal();

        orderWxService.setOrderWcComment(orderCommentWxBo,username);

        return BaseRespVo.ok();
    }

//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------

    @PostMapping("/delete")
    public BaseRespVo delete(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        wxOrderService.deleteOrder(orderId);
        return BaseRespVo.ok();
    }

    @PostMapping("/cancel")
    public BaseRespVo cancel(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        wxOrderService.cancelOrder(orderId);
        return BaseRespVo.ok();
    }

    @PostMapping("/refund")
    public BaseRespVo refund(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        wxOrderService.refundOrder(orderId);
        return BaseRespVo.ok();
    }

    @PostMapping("/confirm")
    public BaseRespVo confirm(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        wxOrderService.confirmOrder(orderId);
        return BaseRespVo.ok();
    }

    @GetMapping("/goods")
    public BaseRespVo goods( Integer orderId,Integer goodsId) {
        OrderGoods orderGoods = orderWxService.selectGoods(orderId, goodsId);

//        CskaoyanmallOrderGoods orderGoods = wxOrderService.selectGoods(orderId, goodsId);
        return BaseRespVo.ok(orderGoods);
    }

    @RequestMapping("/prepay")
    public BaseRespVo prepay(@RequestBody Map map) {
        Integer orderId =  Integer.parseInt((String) map.get("orderId"));
        wxOrderService.prepayGoods(orderId);
        return BaseRespVo.ok();
    }

}
